/**   
* @Title: LocaleMessage.java
* @Package org.xaoyaoyao.cloud.web.message
* @Description: TODO
* @author xaoyaoyao
* @date Feb 11, 2019 3:03:59 PM
* @version V1.0   
*/
package org.xaoyaoyao.cloud.web.message;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

/**
* @ClassName: LocaleMessage
* @Description: TODO
* @author xaoyaoyao
* @date Feb 11, 2019 3:03:59 PM
* 
*/
@Component
public class LocaleMessage {

	@Autowired
	private MessageSource messageSource;

	public String getMessage(String code, Locale locale) {
		return this.getMessage(code, null, "", locale);
	}

	public String getMessage(String code, Object[] args) {
		return this.getMessage(code, args, "");
	}

	public String getMessage(String code, Object[] args, Locale locale) {
		return this.getMessage(code, args, "", locale);
	}

	public String getMessage(String code, Object[] args, String defaultMessage) {
		Locale locale = LocaleContextHolder.getLocale();
		return this.getMessage(code, args, defaultMessage, locale);
	}

	public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
		return messageSource.getMessage(code, args, defaultMessage, locale);
	}
}
